//
//  MineOrderViewController.m
//  beautyLamp
//
//  Created by Tam Kwok To Michael on 2017/9/14.
//  Copyright © 2017年 Tam Kwok To Michael. All rights reserved.
//

#import "MineOrderViewController.h"
#import "BLHeader.h"
#import "SettingTableViewCell.h"
#import "MyOrderViewController.h"
#import "PlaceOrderViewController.h"
//
@interface MineOrderViewController () <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray *titles;
@end

@implementation MineOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)setupUI {
    NSString *userClass = [[NSUserDefaults standardUserDefaults] objectForKey:USERCLASS];
    if ([userClass integerValue] == 2) {
        self.titles = @[@"我的订单",@"下订单"];
    }else {
        self.titles = @[@"我的订单"];
    }
    [self.tableView registerNib:[UINib nibWithNibName:@"SettingTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:ReuseIdentify];
    self.tableView.tableFooterView = [UIView new];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titles.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SettingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ReuseIdentify];
    [cell setupCell:_titles[indexPath.item]];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 56;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UIViewController *controller;
    if (indexPath.row == 0) {
        controller = [[MyOrderViewController alloc] init];
    }else if(indexPath.row == 1) {
        controller = [[PlaceOrderViewController alloc] init];
    }
    [self.navigationController pushViewController:controller animated:YES];
    
}

@end
